$.Model('Question', 
	{
		findAll: 'GET /question/list',
		findOne: 'GET /question?conversation={conversation}',
		create:  'POST /question',
		update:  'PUT /question',
		destroy: 'DELETE /question/?id={id}',
		
		attributes : {
			__className: 'string',
			id: 'integer',
		    text: 'string',
		    answers : 'Answer.models'
		}
	}, {

		init: function( ) {
			this.__className = "Application_Model_Question"
		},
		serialize: function  () {
			var result = JSON.stringify(this, function (key,value){
				var answers = [],i;
				if (key === "answers") {
					for (i=0; i<value.length; i++) {
						answers[i] = value[i];
					}
					value = answers;
				}
				return value;
			});
			
			return result;
		}

	}
);

$.Model('Answer', 
	{
		attributes : {
			__className: 'string',
			id: 'integer',
		    text: 'string',
		    dnaAssignments: 'DNAAssignment.models'
		}
	}, {
		
		init: function( ) {
			this.__className = "Application_Model_Answer"
		}
		
	}
);

$.Model('Dialog', 
	{	
		attributes: {
			__className: 'string',
			id: 'integer',
			question: 'Question.model',
			answer: 'Answer.model',
			relevant: 'integer'
		}
	}, {
		
		init: function () {
			this.__className = "Application_Model_Dialog"
		}
	
	}
);


$.Model('Present', 
	{	
		findAll: 'GET /present/relevant/?conversation={conversation}',
		
		attributes: {
			__className: 'string',
			id: 'integer',
			name: 'string',
			image: 'string'
		}
	}, {
		
		init: function () {
			this.__className = "Application_Model_Present"
		},
		serialize: function () {
			return JSON.stringify(this);
		}
	}
);

$.Model('RegisterConversation', 
	{	
		create:  'POST /conversation',
		attributes: {
			__className: 'string',
			id: 'integer',
			timestamp: 'string',
			present: 'Present.model'
		}
	}, {
		
		init: function () {
			this.__className = "Application_Model_RegisterConversation"
		},
		serialize: function () {
			return JSON.stringify(this);
		}
	}
);

$.Model('FindConversation', 
	{	
		create:  'POST /conversation',
		attributes: {
			__className: 'string',
			id: 'integer',
			timestamp: 'string'
		}
	}, {
		
		init: function () {
			this.__className = "Application_Model_FindConversation"
		},
		serialize: function () {
			return JSON.stringify(this);
		}
	}
);
$.Model('DialogTransfer', 
	{
		create:  'POST /dialog',
	
		attributes: {
			__className: 'string',
			questionId: 'string',
			answerId: 'string',
			relevant: 'integer',
			conversationId: 'string'
		}

	}, {
		
		init: function () {
			this.__className = "Application_Model_DialogTransfer"
		},
		serialize: function () {
			return JSON.stringify(this);
		}
	
	}
);
$.Model('DNA', 
		{
			findAll: 'GET /dna',

			create:  'POST /dna',
			
			attributes: {
				__className: 'string',
				id: 'integer',
				name: 'string'
			}

		}, {
			
			init: function () {
			this.__className = "Application_Model_DNA"
		},
		serialize: function () {
			return JSON.stringify(this);
		}
		
		}
);
$.Model('DNAAssignment', 
		{
			attributes: {
				__className: 'string',
				amount: 'integer',
				presentee: 'boolean',
				dna : 'DNA.model'
			}

		}, {
			
			init: function () {
				this.__className = "Application_Model_DNAAssignment"
			},
			serialize: function () {
				return JSON.stringify(this);
			}
		}
);
